package com.yx1996.test.day02;

import com.yx1996.bean.day02.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;


//一下两个注解可以帮我们自动创建spring容器
//创建容器
@RunWith(SpringJUnit4ClassRunner.class)
//指定创建容器时使用哪个配置文件
@ContextConfiguration("classpath:applicationContext02.xml")
public class test02 {

    //直接创建需要测试的变量并且注入值
    @Resource(name = "user")
    private User u;

    @Test
    //测试Junit测试整合
    public void fun2(){

        System.out.println(u);
    }

   /* @Test
    public void fun1(){

        //获得application对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext02.xml");
        //从对象中获得user对象
        User user = (User) ac.getBean("user");
        //输出user对象
        System.out.println(user);
        //((ClassPathXmlApplicationContext) ac).close();
    }*/
}
